<?php echo $header; ?>
<div class="loginpanel">
    <form method="post" enctype="multipart/form-data" id="form">
        <table id="tbllogin">
            <tr>
                <td colspan="2">
                    <h2 style="color:#6D6D6D;margin-bottom:10px;border-bottom:1px solid #6D6D6D;">Please enter your login details here</h2>
                </td>
            </tr>
            <tr style="display:none;">
                <td colspan="2">
                    <div class="warning">
                    </div>
                </td>
            </tr>
            <tr>
                <td style="margin-top:20px;">
                    <span class="spanlable">Username</span>
                </td>
                <td style="margin-top:20px;">
                    <input type="text" id="txusername" name="txusername" class="txt"/>
                </td>
            </tr>
            <tr>
                <td>
                    <span class="spanlable">Password</span>
                </td>
                <td>
                    <input type="password" id="txtpassword" name="txtpassword" class="txt"/>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <input type="submit" id="btnlogin" value="Login" class="btn" />
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    $("#btnlogin").click(function(){
        if (validate()) {
            loading("show");
            $.ajax({
                url: "<?php echo MAIN_PAGE.'login/loginpost';?>",
                type: 'POST',
                data: {
                    uname: $("#txusername").val(),
                    psw: $("#txtpassword").val()
                },
                dataType: 'json',
                success: function(res){
                    loading('hide');
                    if (!res.status) {
                        $(".warning").text(res.msg).show().closest("tr").show();
                    }
                    else {
                        window.location = "<?php echo MAIN_PAGE.'search';?>";
                    }
                }
            });
        }
        return false;
    });
	
	$('#tbllogin input').keydown(function(e){
        if (e.keyCode == 13) {
            $('#btnlogin').trigger("click");
        }
    });
    
    function validate(){
        $(".warning").closest("tr").hide();
        if ($("#txusername").val() == "") {
			$("#txusername").focus();
            $(".warning").text("Please enter username").show().closest("tr").show();
            return false;
        }
        else 
            if ($("#txtpassword").val() == "") {
				$("#txtpassword").focus();
                $(".warning").text("Please enter password").show().closest("tr").show();
                return false;
            }
        return true;
    }
    
</script>
<?php echo $footer;?>
